home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC17Darts / Darts.c / UMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  4.5 KB  |  186 lines  |  [TEXT/pdos]

  1. /***********************************************************************
  2. *
  3. * darts umenu.c -- Version 3.0 
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements 
  12. * menus in the program.
  13. *
  14. ***********************************************************************/
  15.  
  16. #include <types.h>
  17. #include <desk.h>
  18. #include <intmath.h>
  19. #include <menu.h>
  20. #include <quickdraw.h>
  21. #include <window.h>
  22. #include "darts.h"
  23.  
  24.  
  25. extern unsigned int     crickettTables[NumPlayers][26], score[NumPlayers];
  26. extern unsigned int     gameType, quitFlag, weHaveAWinner;
  27. extern GrafPortPtr      theWindow;
  28. extern WmTaskRec        event;
  29.  
  30.  
  31.  
  32. /************************************************************************************
  33. *
  34. * doAboutItem
  35. *
  36. * Calls AlertWindow to display the about box.  The result is ignored.
  37. *
  38. ************************************************************************************/
  39. void    doAboutItem()
  40. {
  41.     AlertWindow(refIsResource * 2, NULL, 0x0001L);
  42. }
  43.  
  44.  
  45.  
  46. /************************************************************************************
  47. *
  48. * doNewItem
  49. *
  50. * Inits the current window for a new game.  Can be called in response to a 
  51. * menu selection or button press.
  52. *
  53. ************************************************************************************/
  54. void    doNewItem()
  55. {
  56.     unsigned int    j, k;
  57.     unsigned long   along;
  58.  
  59.     score[Player1] = 0;
  60.     score[Player2] = 0;
  61.     
  62.     invalScore(Player1);
  63.     invalScore(Player2);
  64.  
  65.     clearList(Player1);
  66.     clearList(Player2);
  67.     
  68.     for (k = 0; k < NumPlayers; k++) {
  69.         for (j = 15; j < 26; j++) {
  70.             crickettTables[k][j] = 0;
  71.         }
  72.     }
  73.  
  74.     if (gameType == 1) {
  75.         for (k = 25; k >= 15; k--) {
  76.             fixButtonTitle(Player1, k);
  77.             fixButtonTitle(Player2, k);
  78.             if (k == 25) k = 21;
  79.         }
  80.     }
  81.  
  82.     weHaveAWinner = 0;
  83. }
  84.  
  85.  
  86.  
  87. /************************************************************************************
  88. *
  89. * doQuitItem
  90. *
  91. * Sets the global done flag to true in response to the quit menu time.  Can 
  92. * also be called in reponse to the quit button.
  93. *
  94. ************************************************************************************/
  95. void    doQuitItem()
  96. {
  97.     quitFlag++;
  98. }
  99.  
  100.  
  101.  
  102. /***********************************************************************************
  103. *
  104. * doSwitchGames
  105. *
  106. * Switches from Robin to Crickett and back again.  This is called in response
  107. * to selections in the Game menu.  Note:  that if the selected item is
  108. * the current game, then nothing happens.
  109. *
  110. ***********************************************************************************/
  111. void            doSwitchGames(itemNum)
  112. unsigned int    itemNum;
  113. {
  114.     if (itemNum == RobinGameItem) itemNum = 0;
  115.     else itemNum = 1;
  116.  
  117.     if (gameType != itemNum) {
  118.         CloseWindow(theWindow);
  119.         if (!itemNum) startupRobinGame();
  120.         else startupCrickettGame();
  121.         gameType = itemNum;
  122.         doNewItem();
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. /************************************************************************************
  129. *
  130. * doMenu
  131. *
  132. * This resonds to menu selections.  It is called by main event loop in 
  133. * response to all menu selctions (mouse and keyboard).
  134. *
  135. ************************************************************************************/
  136. void    doMenu()
  137. {
  138.     unsigned int    menuNum, itemNum;
  139.  
  140.     menuNum = HiWord (event.wmTaskData);
  141.     itemNum = LoWord (event.wmTaskData);
  142.  
  143.     switch(itemNum) {
  144.         case AboutItem:
  145.             doAboutItem();
  146.             break;
  147.         case NewItem:
  148.             doNewItem();
  149.             break;
  150.         case QuitItem:
  151.             doQuitItem();
  152.             break;
  153.         case UndoItem:
  154.         case CutItem:
  155.         case CopyItem:
  156.         case PasteItem:
  157.         case ClearItem:
  158.             break;
  159.         case RobinGameItem:
  160.         case CrickettGameItem:
  161.             doSwitchGames(itemNum);
  162.             break;
  163.     }
  164.  
  165.     HiliteMenu(0 ,menuNum);     /*Unhighlight the menu title*/
  166. }
  167.  
  168.  
  169.  
  170. /************************************************************************************
  171. *
  172. * setupMenus
  173. *
  174. * Creates the system menu bar with desk accessories.
  175. *
  176. ************************************************************************************/
  177. void    setupMenus()
  178. {
  179.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  180.     SetMenuBar(NULL);
  181.     
  182.     FixAppleMenu(AppleMenuID);          /* Add DAs to apple menu     */
  183.     FixMenuBar();                       /* Set sizes of menus        */
  184.     DrawMenuBar();                      /* ...and draw the menu bar! */
  185. }
  186.